package com.nathan.mq.integration.vender.rocketmq.receive;

import com.nathan.mq.integration.constant.MQVenderCS;
import com.nathan.mq.integration.model.BroadcastMqModel;
import com.nathan.mq.integration.service.IMQMsgReceiver;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

/**
 * rocketMQ消息接收器：仅在vender=rocketMQ时 && 项目实现IMQReceiver接口时 进行实例化 业务：  更新系统配置参数
 *
 * @Description:
 * @Author: zhujunjie
 * @Date: 2021/12/9 17:20
 */
@Component
@ConditionalOnProperty(name = MQVenderCS.YML_VENDER_KEY, havingValue = MQVenderCS.ROCKET_MQ)
@ConditionalOnBean(BroadcastMqModel.IMQReceiver.class)
@RocketMQMessageListener(topic = BroadcastMqModel.MQ_NAME, consumerGroup = BroadcastMqModel.MQ_NAME, messageModel = MessageModel.BROADCASTING)
public class BroadcastRocketMQReceiver implements IMQMsgReceiver, RocketMQListener<String> {

    @Autowired
    private BroadcastMqModel.IMQReceiver mqReceiver;

    /**
     * 接收 【 MQSendTypeEnum.BROADCAST  】 广播类型的消息
     **/
    @Override
    public void receiveMsg(String msg) {
        mqReceiver.receive(BroadcastMqModel.parse(msg));
    }

    @Override
    public void onMessage(String message) {
        this.receiveMsg(message);
    }

}
